<template>
<div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>个人不良记录</span>
        <el-button style="float: none;" type="text" v-on:click="exportExcel1()">导出excel</el-button>
      </div>
      <el-table id="Bad" :data="bad" stripe border >
        <el-table-column label="序号" align="center" width="80">
          <template slot-scope="scope">
            <span>{{ scope.$index }}</span>
          </template>
        </el-table-column>
        <el-table-column label="不良行为内容" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.content }}</span>
          </template>
        </el-table-column>
        <el-table-column label="产生时间" align="center">
          <template slot-scope="scope">
           <span>{{ scope.row.time }}</span>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>谈心谈话记录</span>
        <el-button style="float: none;" type="text" v-on:click="exportExcel2()">导出excel</el-button>
      </div>
       <el-table id="Talk" :data="talk" stripe border >
         <el-table-column label="序号" align="center" width="80">
           <template slot-scope="scope">
             <span>{{ scope.$index }}</span>
           </template>
         </el-table-column>
         <el-table-column label="谈话导员编号" align="center">
           <template slot-scope="scope">
             <span>{{ scope.row.insructor_id}}</span>
           </template>
         </el-table-column>
         <el-table-column label="谈话导员姓名" align="center">
           <template slot-scope="scope">
            <span>{{ scope.row.insructor_name }}</span>
           </template>
         </el-table-column>
         <el-table-column label="谈话主题、内容" align="center">
           <template slot-scope="scope">
             <span>{{ scope.row.comment }}</span>
           </template>
         </el-table-column>
         <el-table-column label="谈话时间" align="center">
           <template slot-scope="scope">
             <span>{{ scope.row.talk_time }}</span>
           </template>
         </el-table-column>
       </el-table>
    </el-card>
</div>
</template>
<script>
import FileSaver from 'file-saver'
import XLSX from 'xlsx'
export default {
  name: "UserDaily",
  props:['id'],
  data() {
    return {
        bad:[],
        talk:[]
    }

  },
  mounted:function(){
    var url1='/daily/query';
    var url2='/daily/talk_query';
        this.$http.get(url1,{params:this.id}).then((res) =>{
                console.log(res);
                var jsonObject = res.data;
                this.bad=jsonObject.bad;
            })
            .catch((err) => {
                          this.$notify.error({
                            title: "错误",
                            message: "服务器内部错误",
                          });
                        });
        this.$http.get(url2,{params:this.id}).then((res) =>{
                console.log(res);
                var jsonObject = res.data;
                this.talk=jsonObject.talks;
            })
            .catch((err) => {
                          this.$notify.error({
                            title: "错误",
                            message: "服务器内部错误",
                          });
                        });
  },
  methods: {
    show() {
      console.log(this.$route.params.id)
    },
    exportExcel1 () {
        /* generate workbook object from table */
         let xlsxParam = { raw: true } // 导出的内容只做解析，不进行格式转换
         let wb = XLSX.utils.table_to_book(document.querySelector('#Bad'), xlsxParam);
         /* get binary string as output */
         let wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' });
         try {
             FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), '不良行为记录.xlsx');
         } catch (e)
         {
             if (typeof console !== 'undefined')
                 console.log(e, wbout)
         }
         return wbout
     },
    exportExcel2 () {
        /* generate workbook object from table */
         let xlsxParam = { raw: true } // 导出的内容只做解析，不进行格式转换
         let wb = XLSX.utils.table_to_book(document.querySelector('#Talk'), xlsxParam);
         /* get binary string as output */
         let wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'array' });
         try {
             FileSaver.saveAs(new Blob([wbout], { type: 'application/octet-stream' }), '谈心谈话记录.xlsx');
         } catch (e)
         {
             if (typeof console !== 'undefined')
                 console.log(e, wbout)
         }
         return wbout
     }
  }
}
</script>
<style scoped>
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both
}

.box-card {
  width: 700px;
}
</style>
